<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ include file="/view/common/init.jsp"%>
<title>Cập nhật scope</title>
<script type="text/javascript">
function submitEditScopeForm(){
	if (!check('scope.scopeName', 'Tên scope', null, 40)){
		return false;
	}
	if ( $('scope.scopeName').value !=  $('scope.scopeNameOld').value){
		new Ajax.Request(base_url + 'scope/nameIsUsed.do?scope.scopeName=' + $('scope.scopeName').value, {
			method : 'post',
			onSuccess : function(transport) {
				var data = transport.responseText.evalJSON();
				// Init Countries combo
				if (data.nameIsUsed=='false'){
					$('editScopeForm').submit(); 	
				} else {
					alert('Tên scope đã tồn tại! Hãy chọn lại');
					setTimeout(function(){$('scope.scopeName').focus();}, 10);		
				}
			},
			onFailure : function() {
				alert('Something went wrong...');
			}
		});		
	} else {
		$('editScopeForm').submit();
	} 	
}
</script>
<center>
<div class="header">CẬP NHẬT SCOPE</div>
<div style="width: 980px;">
<s:form id="editScopeForm" action="editComplete.do">
<input type="hidden" value="<c:out value="${scope.scopeId}"/>" name="scope.scopeId"></input>
<input type="hidden" value="<c:out value="${scope.scopeName}"/>" id="scope.scopeNameOld"></input>
<table class="tbl_info" border="0" width="613">
	<tbody>
		<tr>
			<td class="hed" colspan="2" />CẬP NHẬT SCOPE</td>
		</tr>
		<tr><td>Tên scope<span class="error">&nbsp;*</span></td>
		<td>
			<s:textfield name="scope.scopeName" 
				cssClass="require" id="scope.scopeName" />	
		</td></tr>	</tbody>
</table>
<div style="margin-top: 30px;">
	<button type="button" onclick="history.back();">Hủy bỏ</button>
	<button type="button" onclick="submitEditScopeForm();">Đồng ý</button>
</div>
</s:form>
</div>
</center>